import 'package:flutter/material.dart';
import 'package:xindong/common/xindong_sezhi.dart';
import 'package:xindong/manager/xindong_page_singleton.dart';
import 'package:xindong/manager/xindong_user_controller.dart';
import 'package:xindong/models/user/xindong_home_user.dart';
import 'package:xindong/models/user/xindong_other_user.dart';
import 'package:xindong/res/assets_res.dart';
import 'package:xindong/routes/conversation/model/xindong_liaotian_detail_class.dart';
import 'package:xindong/utils/xindong_conversion_util.dart';
import 'package:xindong/utils/xindong_image_util.dart';

class XinDongUserCardCell extends StatelessWidget {
  final XinDongHomeUser model;

  const XinDongUserCardCell({Key? key, required this.model}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () => XinDongPageSingleton.instance.jumpToSpace(model),
      behavior: HitTestBehavior.opaque,
      child: Container(
        width: double.infinity,
        height: double.infinity,
        clipBehavior: Clip.antiAlias,
        decoration: BoxDecoration(borderRadius: BorderRadius.circular(16), color: Colors.white),
        child: Stack(
          children: [
            ImageUtil.avatarUrl(model.user_head),
            Positioned(
              top: 10,
              left: 10,
              child: ImageUtil.asset(model.is_online == 1 ? AssetsRes.ICON_ONLINE : AssetsRes.ICON_OFFLINE, width: 12),
            ),
            // Positioned(
            //   top: 10,
            //   left: 10,
            //   child: model.isAnchor
            //       ? XinDongCallingStatus(user: model)
            //       : Container(
            //     height: 20,
            //     padding: const EdgeInsets.only(left: 6, right: 6),
            //     decoration: BoxDecoration(color: Colors.black26, borderRadius: BorderRadius.circular(10)),
            //     child: Row(
            //       children: [
            //         if (model.onLine == 1)
            //           Padding(
            //             padding: const EdgeInsets.only(right: 4.0),
            //             child: Icon(Icons.brightness_1, color: XinDongColors.statusCorrectColor, size: 8),
            //           ),
            //         Text(
            //           model.onLine == 1 ? "在线" : XinDongCalendarHelper.htmy_loginTime(model.lastTime),
            //           style: const TextStyle(fontSize: 12, color: Colors.white, height: 1.3),
            //         ),
            //       ],
            //     ),
            //   ),
            // ),
            Positioned(
              bottom: 0,
              left: 0,
              right: 0,
              child: Container(
                padding: const EdgeInsets.all(10),
                clipBehavior: Clip.antiAlias,
                decoration: BoxDecoration(
                  gradient: LinearGradient(
                    begin: Alignment.topCenter,
                    end: Alignment.bottomCenter,
                    stops: const [0.0, 1.0],
                    colors: [Colors.black.withOpacity(0.0), Colors.black.withOpacity(0.6)],
                  ),
                ),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  mainAxisSize: MainAxisSize.min,
                  children: [
                    // 昵称
                    Text(
                      XinDongConversionUtil.xindong_breakWord(model.user_name),
                      maxLines: 1,
                      overflow: TextOverflow.ellipsis,
                      style: const TextStyle(fontSize: 16, color: DZColors.white, fontWeight: FontWeight.w500),
                    ),
                    const SizedBox(height: 4),
                    // XinDongMainAlbumList(dataList: model.photolist, maxCount: 4),
                    const SizedBox(height: 5),
                    Row(
                      children: [
                        Flexible(
                          child: Text(
                            // "${model.user_age}岁 ${model.city} 距离${model.user_distance}",
                            "${model.user_age}岁 ${model.city}",
                            maxLines: 1,
                            overflow: TextOverflow.ellipsis,
                            style: const TextStyle(fontSize: 12, color: DZColors.white),
                          ),
                        ),
                      ],
                    ),
                  ],
                ),
              ),
            ),

            Positioned(
              bottom: 10,
              right: 10,
              child: GestureDetector(
                onTap: () {
                  XinDongLiaoTianDetailClass detailClass = XinDongLiaoTianDetailClass();
                  detailClass.self = XinDongUserController.to.baseUser;
                  detailClass.another = XinDongOtherUser.fromJson(XinDongConversionUtil.modelToMap(model));
                  XinDongPageSingleton.instance.calling(model: detailClass);
                },
                child: ImageUtil.asset(AssetsRes.BUTTON_CALL, width: 51, height: 20),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
